package com.service.impl;

import com.dao.ReceivingAddressDao;
import com.dao.impl.ReceivingAddressDaoImpl;
import com.pojo.ReceivingAddress;
import com.service.ReceivingAddressService;

import java.util.List;

public class ReceivingAddressServiceImpl implements ReceivingAddressService {
    private ReceivingAddressDao dao = new ReceivingAddressDaoImpl();

    @Override
    public List<ReceivingAddress> selectByUserID(String userID) {
        return dao.selectByUserID(userID);
    }

    @Override
    public boolean addRA(ReceivingAddress receivingAddress) {
        if (receivingAddress.getIsDefault()==1){
            System.out.println(receivingAddress.getIsDefault());
            dao.updateRAByUserID(receivingAddress.getUserId());
        }

        return dao.addRA(receivingAddress)>0;
    }

    @Override
    public boolean updateRA(ReceivingAddress receivingAddress) {
        if (receivingAddress.getIsDefault()==1){
            dao.updateRAByUserID(receivingAddress.getUserId());
        }
        return dao.updateRA(receivingAddress)>0;
    }

    @Override
    public boolean deleteRA(String id) {
        return dao.deleteRA(id)>0 ;
    }

    @Override
    public ReceivingAddress findByID(String id) {
        return dao.selectByID(id);
    }
}
